<template>
	<view class="container">
		<view class="input-box">
			<input v-model="formData.content" placeholder-class="input-placeholder" />
			<view class="input-line"></view>
		</view>
		<view class="save-btn" @tap="save">保存</view>
	</view>
</template>

<script>
	import { http, showToastMsg } from '../../utils'
	
	export default {
		data() {
			return {
				formData: {
					type: 0,
					content: ''
				},
				userInfo: null
			}
		},
		
		onLoad(options) {
			let t = options.t
			this.formData.type = t
			this.userInfo = uni.getStorageSync('userInfo')
			if (t == 1) { // 修改地区
				this.formData.content = this.userInfo.userArea
			} else if (t == 2) { // 修改学校签名
				this.formData.content = this.userInfo.userGreet
			}
		},
		
		methods: {
			
			save() {
				const that = this
				if (that.formData.content.length <= 0) {
					return showToastMsg('请输入内容')
				}
				
				http('/user/modify', that.formData, {loadingTitle: '提交中'}).then(res => {
					if (res.code == 20000) {
						http('/no-login/islogin').then(isLoginRes => {
							uni.setStorageSync('userInfo', isLoginRes.data.userInfo)
							showToastMsg(res.message)
							uni.redirectTo({
								url: '/pages/teacher_zone_index/teacher_zone_index'
							})
						})
					}
				})
			}
			
		}
	}
</script>

<style>
	.container {
		width: 750rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	
	.input-box {
		width: 700rpx;
		margin-top: 40rpx;
	}
	
	.input-box input {
		font-size: 30rpx;
		color: #333333;
	}
	
	.input-placeholder {
		font-size: 30rpx;
	}
	
	.input-line {
		width: 100%;
		height: 2rpx;
		background-color: #45d6b7;
		margin-top: 20rpx;
	}
	
	.save-btn {
		width: 700rpx;
		height: 78rpx;
		background-image: linear-gradient(90deg, #ff8806 0%, #fbae2b 100%), linear-gradient(#4482f8, #4482f8);
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		color: #ffffff;
		font-size: 36rpx;
		border-radius: 40rpx;
		margin-top: 100rpx;
	}
</style>
